package com.hls.handler;

import com.hls.domain.Result;
import com.hls.exception.BoyException;
import com.hls.util.ResultUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by huangliusong on 2017/7/22.
 */
@ControllerAdvice
public class ExceptionHandle {
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handler(Exception e){
        if(e instanceof BoyException){
            BoyException boyException=(BoyException)e;
            return ResultUtil.error(boyException.getCode(),boyException.getMessage());
        }else{
            return ResultUtil.error(-1,"未知错误");
        }

    }
}
